package com.bida.controller.admin;


import com.bida.domain.dto.CategoryDTO;
import com.bida.domain.po.Category;
import com.bida.result.PageResult;
import com.bida.result.Result;
import com.bida.service.ICategoryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 菜品及套餐分类 前端控制器
 * </p>
 *
 * @author ly
 * @since 2024-09-06
 */
@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Resource
    private ICategoryService categoryService;

    /**
     * 修改分类
     * @param categoryDTO
     * @return
     */
    @PutMapping
    public Result updateCategoryInfoById(@RequestBody CategoryDTO categoryDTO){
        return categoryService.updateCategoryInfoById(categoryDTO);
    }

    /**
     * 分页查询分类
     * @param name
     * @param page
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> pageGetCategory(String name,Integer page, Integer pageSize,Integer type) {
        return categoryService.pageGetCategory(name,page, pageSize,type);
    }

    /**
     * 启用、禁用分类
     * @param status
     * @param id
     * @return
     */
    @PostMapping("/status/{status}")
    public Result updateStatusById(@PathVariable Integer status,Long id){
        return categoryService.updateStatusById(status,id);
    }

    /**
     * 新增分类
     * @param categoryDTO
     * @return
     */
    @PostMapping
    public Result insertNewCategory(@RequestBody CategoryDTO categoryDTO){
        return categoryService.insertNewCategory(categoryDTO);
    }

    /**
     * 根据 id 删除分类
     * @param id
     * @return
     */
    @DeleteMapping
    public Result deleteCategoryById(Long id){
        return categoryService.deleteCategoryById(id);
    }

    /**
     * 根据类型查询分类 分页
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result<List<Category>> getPageCategoryList(Integer type){
        return categoryService.getPageCategoryList(type);
    }

}
